<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * Banner library class
 *
 * Banner information's CRUD.
 *
 */
class Banner_lib
{
	/**
	 * Constructor
	 *
	 * Load all banner model.
	 */
	public function __construct()
	{
		$this->CI = &get_instance();
		$this->CI->load->model('pf/app/blacklist_model');
		$this->CI->load->model('pf/advertise/banner_info_model');
	}

	/**
	 * Get banner information regarding location id.
	 *
	 * @param	integer	location id
	 * @param	integer	orientation. 0: portrait view; 1: landscape view
	 * @return	object	banner objects
	 */
	public function get_by_loc($loc = 0, $orientation = 0,$os)
	{
		if($loc <= 0)
			return array();
		
		$banners = $this->CI->banner_info_model->get_by_loc($loc, 5, $orientation,$os);
		$black_os = get_os($os);
		$black_game_list = $this->CI->blacklist_model->get_all_appids(2,$black_os);
		$list = array();
		foreach ($banners as $b)
		{
			if(in_array($b['val'],$black_game_list))
				continue;
			
			$banner['type'] = $b['type'];
			$banner['val'] = $b['val'];
			if($orientation <= 0)
				$banner['thumb'] = $this->CI->config->item('res_domain').$b['thumb_p'];
			else if($orientation >= 1)
				$banner['thumb'] = $this->CI->config->item('res_domain').$b['thumb_l'];
				
			array_push($list, $banner);
		}
		return $list;
	}
}